package exportSystem.statistics;

import java.util.HashMap;

import gameEngine.agents.observationSystem.samples.Sample;

public class TurnLogImpl implements TurnLog {

	private double score=0;
	private HashMap<Integer,Double> agentScore=new HashMap<Integer, Double>();
	private HashMap<Integer,Integer> timesPlayed=new HashMap<Integer, Integer>();
	
	public void readSample(Sample s){
		score+=s.getScore();
		double sum;
		int turns;
		if(agentScore.get(s.getID())!=null){
			sum=agentScore.get(s.getID())+s.getScore();
			turns=timesPlayed.get(s.getID())+1;
			agentScore.remove(s.getID());
			timesPlayed.remove(s.getID());
		}else{
			sum=s.getScore();
			turns=1;
		}

		agentScore.put(s.getID(), sum);
		timesPlayed.put(s.getID(), turns);
	}
	
	public double getAvaregeScore(int turns){
		return (score/turns);
	}
	
	public double getAgentAvaregeScore(int id){
		if(agentScore.get(id)==null){
			return 0;
		}
		return agentScore.get(id)/timesPlayed.get(id);
	}
	
	public int getAgentTimesPlayed(int id){
		if(timesPlayed.get(id)==null){
			return 0;
		}
		return timesPlayed.get(id); 
	}
	
}
